package com.wd.tech.view.activity;

import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.wd.tech.R;

import com.wd.tech.bean.FindSingRecordingBean;
import com.wd.tech.mvp.base.BaseActivity;
import com.wd.tech.mvp.base.BasePresenter;
import com.wd.tech.mvp.presenter.PresenterImpl;
import com.wd.tech.mvp.util.MyUrl;
import com.wd.tech.view.fragment.SheQu;
import com.wd.tech.view.fragment.XiaoXi;
import com.wd.tech.view.fragment.ZiXun;

import java.io.Serializable;
import java.util.List;

public class MainActivity extends BaseActivity {
    FragmentManager manager;
    RadioGroup radioGroup;
    ImageView qian;
    Fragment fragment;
    TextView textView,righttextView;
    ImageView tx;
    Button button;
    DrawerLayout layout;
    private String s;
    //123123123
    //123123123
    //3123123123
    //123123

    TextView textView_Shoucang,textView_guanzhu,textView_tiezi,textView_tongzhi,textView_jifen,textView_renwu,textView_shezhi;

    LinearLayout linner;

    RecyclerView recyclerView;
    private String headPic;
    private String phone;
    private String nickName;

    @Override
    protected void startCoding() {

        nickName = getIntent().getStringExtra("nickName");

        Log.e("aaa","用户名字:"+ nickName);

        Intent intent = getIntent();
        headPic = intent.getStringExtra("headPic");
        phone = intent.getStringExtra("phone");


        textView.setText(nickName);












        Log.e("aaa",""+s);


        final ZiXun ziXun = new ZiXun();

        final XiaoXi xiaoXi = new XiaoXi();

        final SheQu sheQu = new SheQu();



        manager=getSupportFragmentManager();

        manager.beginTransaction()
                .add(R.id.frag,ziXun)
                .add(R.id.frag,xiaoXi)
                .add(R.id.frag,sheQu)
                .show(ziXun).hide(xiaoXi).hide(sheQu)
                .commit();


        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio1:
                        manager.beginTransaction()
                                .show(ziXun).hide(xiaoXi).hide(sheQu)
                                .commit();
                        break;

                    case R.id.radio2:
                        manager.beginTransaction()
                                .hide(ziXun).show(xiaoXi).hide(sheQu)
                                .commit();
                        break;

                    case R.id.radio3:
                        manager.beginTransaction()
                                .hide(ziXun).hide(xiaoXi).show(sheQu)
                                .commit();
                        break;
                }
            }
        });




        textView_Shoucang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, My_Shoucang.class);
                startActivity(intent);
            }
        });

        textView_guanzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, My_Guanzhu.class);
                startActivity(intent);
            }
        });

        textView_tiezi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, My_Tiezi.class);
                startActivity(intent);
            }
        });

        textView_tongzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, My_Tongzhi.class);
                startActivity(intent);
            }
        });

        textView_renwu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, My_Renwu.class);
                startActivity(intent);
            }
        });

        textView_jifen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, My_Jifen.class);
                startActivity(intent);
            }
        });

        textView_shezhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, My_Shezhi.class);
                intent.putExtra("headPic",headPic);
                intent.putExtra("phone",phone);
                intent.putExtra("nickName",nickName);
                startActivity(intent);
            }
        });

        qian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                mPresenter.startgetInfo(MyUrl.FIND_RECORDING,FindSingRecordingBean.class);
            }
        });




    }

    @Override
    protected BasePresenter initPresenter() {
        return new PresenterImpl();
    }

    @Override
    protected void initView() {

        linner=findViewById(R.id.linner);

        textView_Shoucang=findViewById(R.id.zixun_shoucang);
        textView_guanzhu=findViewById(R.id.zixun_guanzhu);
        textView_tiezi=findViewById(R.id.zixun_tiezi);
        textView_tongzhi=findViewById(R.id.zixun_tongzhi);
        textView_renwu=findViewById(R.id.zixun_renwu);
        textView_jifen=findViewById(R.id.zixun_jifen);
        textView_shezhi=findViewById(R.id.zixun_shezhi);
        qian=findViewById(R.id.qian);



        radioGroup=findViewById(R.id.rg1);
        textView=findViewById(R.id.celaname);

    }

    @Override
    protected int Layout() {
        return R.layout.activity_main;
    }

    @Override
    public void onSuccess(Object o) {


        if (o instanceof FindSingRecordingBean){

            List<String> result = ((FindSingRecordingBean) o).getResult();
            Intent intent = new Intent(MainActivity.this,MyDateActivity.class);
            intent.putExtra("tmd",(Serializable) result);
            startActivity(intent);
        }
    }

    @Override
    public void onError(String error) {

    }



    public void left(View v){
        layout.openDrawer(Gravity.LEFT);
        layout.closeDrawer(Gravity.LEFT);/*重点，自动关闭侧边栏*/
    }



    public void name(View view) {
        Toast.makeText(this, "123", Toast.LENGTH_SHORT).show();
    }
}
